<template>
 <div class="app-container">
     <!-- 工具按钮 -->
    <el-card class="operate-container" shadow="never">
      <i class="el-icon-tickets" style="margin-top: 5px"></i>
      <span style="margin-top: 5px">数据列表</span>
    </el-card>

     <!-- 表格 -->
    <el-table
      :data="list"
      border
      stripe
      @selection-change="handleSelectionChange">
      <el-table-column type="selection"/>
      <el-table-column label="id" prop="id" width="200"></el-table-column>
      <el-table-column label="姓名" prop="name" width="300"></el-table-column>
      <el-table-column label="邮箱" prop="email" width="300"></el-table-column>

      <el-table-column label="操作" width="300" align="center">
        <template slot-scope="scope">
            <el-button type="text" @click="getcandidate(scope.row.email)">查看报告</el-button> 
            <el-dialog title="测评报告" :visible.sync="dialogFormVisible">
                <el-form :model="form">

                    <el-form-item label="邮箱" :label-width="formLabelWidth">
                        <el-input v-model="form.email":disabled="true" autocomplete="off"></el-input>
                    </el-form-item>
                    <el-form-item label="报告名字" :label-width="formLabelWidth">
                        <el-input v-model="form.reportName":disabled="true" autocomplete="off"></el-input>
                    </el-form-item>
                    <el-form-item label="更新时间" :label-width="formLabelWidth">
                        <el-input v-model="form.updateTime":disabled="true" autocomplete="off"></el-input>
                    </el-form-item>
                    <el-form-item label="报告内容" :label-width="formLabelWidth">
                        <el-input type="textarea" v-model="form.report":disabled="true" autocomplete="off" resize="none" :rows="10" maxlength="500" show-word-limit style="width:100%"></el-input>
                    </el-form-item>
                </el-form>
                <div slot="footer" class="dialog-footer">
                    <el-button @click="dialogFormVisible = false">取 消</el-button>
                     <router-link :to="'/examination/'+form.email">
                     <el-button type="primary">打分</el-button>
                    </router-link> 
                </div>
                </el-dialog>    
        </template>
      </el-table-column>
    </el-table>


    <!-- 分页组件 -->
    <el-pagination
      :current-page="page"
      :total="total"
      :page-size="limit"
      :page-sizes="[5, 10, 20, 30, 40, 50, 100]"
      style="padding: 30px 0; text-align: center;"
      layout="total, sizes, prev, pager, next, jumper"
      @size-change="changePageSize"
      @current-change="changeCurrentPage"
    />
 </div>

</template>

<script>
import indexApi from '@/api/examination/index.js'
import indexApi1 from '@/api/summary/index.js'
  export default {
    data() {
      return {
        list: [], // 讲师列表
        total: 0, // 总记录数
        page: 1, // 页码
        limit: 5, // 每页记录数
        email: document.cookie.split("vue_admin_template_token=")[1].split(";")[0],
        dialogFormVisible: false,
        form: {
              reportName:'',
              report:'',
              updateTime:'',
              email:'',
              name:''
        },
        formLabelWidth: '120px'
      }
    },
     created() { // 在渲染之前执行
         this.fetchData();
  
    },
    mounted() { // 在渲染之后执行   

       
    },
    methods: {

        fetchData(){
            indexApi.getnames(this.page, this.limit,this.email).then(response => {
                this.list = response.data.records
                console.log(this.list)
                this.total = response.data.total
            })
        },

        
    //根据邮箱获取报告信息信息
    getcandidate(email){
        indexApi1.getcandidate(email).then(response => {
            if(response.data!=null){
                this.dialogFormVisible = true
                this.form=response.data
            }else{
                this.$confirm('该干部还未写报告, 是否继续打分?', '提示', {
                confirmButtonText: '打分',
                cancelButtonText: '取消',
                type: 'warning'
                }).then(() => {
                this.$message({
                    type: 'success',
                    message: '前往打分!'
                });
                    this.$router.push(`/examination/${email}`)
                })
                .catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消'
                });          
                });
            }
            
        })
    },
    submitForm(email){
        console.log(email)
        this.$router.push('/examination')
    },
      
      
        // 每页记录数改变，size：回调参数，表示当前选中的“每页条数”
    changePageSize(size) {
      this.limit = size
      this.fetchData()
    },

    // 改变页码，page：回调参数，表示当前选中的“页码”
    changeCurrentPage(page) {
      this.page = page
      this.fetchData()
    },
    


    
    handleSelectionChange(selection){
      this.multipleSelection=selection
    },



    },
}
</script>